#!/usr/bin/env bash
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2019, Intel Corporation
#
#
# libpmempool_rm_remote/TEST4 -- test for pmempool_rm with remote replica
#
# Remove pool when it is opened
#

. ../unittest/unittest.sh

require_test_type medium

require_nodes 2

require_node_libfabric 0 $RPMEM_PROVIDER
require_node_libfabric 1 $RPMEM_PROVIDER

setup

init_rpmem_on_node 1 0

create_poolset $DIR/pool.set 8M:${NODE_DIR[1]}pool.1:x \
        m ${NODE_ADDR[0]}:remote.set
create_poolset $DIR/remote.set 8M:${NODE_DIR[0]}/remote.1:x

copy_files_to_node 0 ${NODE_DIR[0]} $DIR/remote.set
copy_files_to_node 1 ${NODE_DIR[1]} $DIR/pool.set

rm_files_from_node 0 ${NODE_DIR[0]}remote.1
rm_files_from_node 1 ${NODE_DIR[1]}pool.1
expect_normal_exit run_on_node 1 ../pmempool create obj ${NODE_DIR[1]}pool.set

check_files_on_node 1 pool.set pool.1
check_files_on_node 0 remote.set remote.1

# without force pmempool_rm should fail
expect_normal_exit run_on_node 1 ./libpmempool_rm$EXESUFFIX -o \
	${NODE_DIR[1]}pool.set
check_files_on_node 1 pool.set pool.1
check_files_on_node 0 remote.set remote.1

# with force pmempool_rm should also fail
expect_normal_exit run_on_node 1 ./libpmempool_rm$EXESUFFIX -of \
	${NODE_DIR[1]}pool.set
check_files_on_node 1 pool.set pool.1
check_files_on_node 0 remote.set remote.1

pass
